package com.mms.dbacess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.mms.entity.User;
import com.mms.entity.UserRole;

	

public class SelectUsers {
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		String sql="SELECT username,`password`,enabled,role,manager from `user`��";
		Class.forName("com.mysql.cj.jdbc.Driver");
		Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/grtsmms", "root", "root");
		PreparedStatement stme=conn.prepareStatement(sql);
		ResultSet re =stme.executeQuery();
		List<User> ls= new ArrayList<User>();
		while (re.next()) {
			String username=re.getString("username");
			String password=re.getString("password");
			boolean enabled=re.getBoolean("enabled");
	        Enum<UserRole> role=Enum.valueOf(UserRole.class, re.getString("role"));
	        String manager=re.getString("manager");
	        User user=new User();
	        user.setUsername(username);
	        user.setEnabled(enabled);
	        user.setManager(manager);
	        user.setPassword(password);
	        user.setRole((UserRole) role);
	        ls.add(user);
		}
		System.out.println(ls);
	}
}
